import request from '@/utils/request';
import { Pagination } from '@/types/global';

// 角色数据
export interface RoleData {
    id?: number;
    name?: string;
    code?: string;
    sort?: number;
    status?: number;
}

// 角色授权资源数据
export interface RoleResourceData {
    roleId?: number;
    resourceIds?: [];
}

// 用户赋予角色
export interface UserRoleData {
    userId?: number;
    roleIds?: [];
}

// 查询参数
export interface RoleParams extends Partial<RoleData> {
    current?: number;
    size?: number;
    startDate?: string;
    endDate?: string;
}

// 角色列表(分页)
export function pageRole(params: RoleParams) {
    return request<Pagination<RoleData[]>>('get', '/role/page', { params })
}

// 角色列表
export function listRole(params: RoleParams) {
    return request<RoleData[]>('get', '/role/list', { params })
}

// 添加角色
export function saveRole(data: RoleData) {
    return request('post', '/role', data)
}

// 修改角色
export function updateRole(data: RoleData) {
    return request('put', '/role', data)
}

// 修改角色状态
export function updateRoleStatus(data: RoleData) {
    return request('put', '/role/status', data)
}

// 删除角色
export function deleteRole(ids: any) {
    return request('delete', '/role/' + ids)
}

// 根据角色获取资源信息
export function roleResource(params: any) {
    return request('get', '/role/resource', { params })
}

// 角色赋予权限
export function authResource(data: RoleResourceData) {
    return request('post', '/role/resource/authorization', data)
}

// 用户赋予角色
export function authUser(data: UserRoleData) {
    return request('put', '/role/user/authorization', data)
}

